﻿using System.Timers;
using System;

namespace Calendar.Domain
{   
    public abstract class PomodoroState
    {
        int _totalTime;
        public int TotalTime
        {
            get
            {
                return _totalTime * 60;
            }
            set
            {
                _totalTime = value;
            }
        }

        public int Counter { get; set; }
        public UpdateHandler Update = null;
        public ChangeStateHandler ChangeState = null;
        Timer _timer;

        public void Initialize(int totalTime)
        {
            TotalTime = totalTime;
            Counter = 0;
            _timer = new Timer(1000);
            _timer.Elapsed += TickTimer;     
        }

        public void TickTimer(object source, ElapsedEventArgs e)
        {
            if (Counter < TotalTime-1)
            {
                Counter++;
            }
            else
            {
                ChangeState.Invoke();//換成休息時間
                StopTimer();

            }
            Update.Invoke();
        }

        public void StartTimer()//開始記時
        {
            _timer.Start();
        }

        public void StopTimer()//暫停記時
        {
            _timer.Stop();
        }

        public abstract PomodoroState NextPomodoroState { get; }
        public abstract string TimeLabelText { get; }
        public abstract int PomodoroProgressBarValue { get; }
    }
}
